function jump(nums) {
  let ans = 0, end = 0, maxIndex = 0
  for (let i = 0; i < nums.length - 1; i++) {
    maxIndex = Math.max(maxIndex, i + nums[i])
    if (i === end) {
      end = maxIndex
      ans++
    }
  }
  return ans
}